<template>
  <div>
    <div>
      <MkCard>
        <BaseSearchForm :isShowBack="false" v-model:search-param="checkParam" @search="search" :rangeDay="30" />
      </MkCard>
      <MkCard>
        <MkScan placeholder="请扫描标本条码" @getScanInfo="getScanInfo" ref="scanRef" />
        <MkTable height="580px" :data="showList">
          <MkColumn label="医院条码" prop="hospitalBarcode" />
          <MkColumn label="标本类型" prop="specimenType" />
          <MkColumn label="标本来源" prop="specimenSource" />
          <MkColumn label="病人id" prop="patientId" />
          <MkColumn label="病人姓名" prop="patientName" />
          <MkColumn label="床号" prop="bedNumber" />
          <MkColumn label="病人电话" prop="patientPhone" />
          <MkColumn label="送检科室" prop="department" />
          <MkColumn label="送检医生" prop="doctor" />
          <MkColumn label="医生电话" prop="doctorPhone" />
          <MkColumn label="采样时间" prop="samplingTime" />
          <MkColumn label="性别" prop="gender" />
          <MkColumn label="出生时间" prop="birthTime" />
          <MkColumn label="年龄" prop="age" />
          <MkColumn label="年龄单位" prop="ageUnit" />
          <MkColumn label="医嘱" prop="medicalAdvice" />
        </MkTable>

      </MkCard>
    </div>
    
  </div>

</template>

<script lang='ts' setup>
import { ElMessageBox } from 'element-plus';

// 定义数据类型
interface specimenData {
  hospitalBarcode: string;
  specimenType: string;
  specimenSource: string;
  patientId: string;
  patientName: string;
  bedNumber: string;
  patientPhone: string;
  department: string;
  doctor: string;
  doctorPhone: string;
  samplingTime: string;
  gender: string;
  birthTime: string;
  age: number;
  ageUnit: string;
  medicalAdvice: string;
}
const checkParam = ref({
  keyword: undefined,
  startCreationTime: undefined,
  endCreationTime: undefined
})

const list = ref<specimenData[]>([
  {
    hospitalBarcode: '10001',
    specimenType: '血液',
    specimenSource: '门诊',
    patientId: 'P001',
    patientName: '张三',
    bedNumber: '101',
    patientPhone: '13812345678',
    department: '内科',
    doctor: '李医生',
    doctorPhone: '13987654321',
    samplingTime: '2025-02-02 10:00:00',
    gender: '男',
    birthTime: '1990-02-02',
    age: 35,
    ageUnit: '岁',
    medicalAdvice: '常规检查'
  },
  {
    hospitalBarcode: '10002',
    specimenType: '尿液',
    specimenSource: '住院',
    patientId: 'P002',
    patientName: '李四',
    bedNumber: '202',
    patientPhone: '13678901234',
    department: '外科',
    doctor: '王医生',
    doctorPhone: '13543218765',
    samplingTime: '2025-02-02 14:30:00',
    gender: '女',
    birthTime: '1985-05-15',
    age: 40,
    ageUnit: '岁',
    medicalAdvice: '肾功能检查'
  },
  {
    hospitalBarcode: '10003',
    specimenType: '组织',
    specimenSource: '手术室',
    patientId: 'P003',
    patientName: '王五',
    bedNumber: '303',
    patientPhone: '13711112222',
    department: '五官科',
    doctor: '赵医生',
    doctorPhone: '13422223333',
    samplingTime: '2025-02-03 09:15:00',
    gender: '男',
    birthTime: '1995-08-20',
    age: 30,
    ageUnit: '岁',
    medicalAdvice: '病理检查'
  },
  {
    hospitalBarcode: '10004',
    specimenType: '粪便',
    specimenSource: '急诊',
    patientId: 'P004',
    patientName: '孙六',
    bedNumber: '404',
    patientPhone: '13955556666',
    department: '急诊科',
    doctor: '陈医生',
    doctorPhone: '13866667777',
    samplingTime: '2025-02-04 16:45:00',
    gender: '男',
    birthTime: '1992-11-10',
    age: 33,
    ageUnit: '岁',
    medicalAdvice: '肠道检查'
  },
  {
    hospitalBarcode: '10005',
    specimenType: '唾液',
    specimenSource: '体检中心',
    patientId: 'P005',
    patientName: '周七',
    bedNumber: '505',
    patientPhone: '13599998888',
    department: '体检科',
    doctor: '杨医生',
    doctorPhone: '13688889999',
    samplingTime: '2025-02-05 11:20:00',
    gender: '女',
    birthTime: '1998-03-05',
    age: 27,
    ageUnit: '岁',
    medicalAdvice: '口腔检查'
  },
  {
    hospitalBarcode: '10006',
    specimenType: '脑脊液',
    specimenSource: '神经内科',
    patientId: 'P006',
    patientName: '吴八',
    bedNumber: '606',
    patientPhone: '13477770000',
    department: '神经内科',
    doctor: '刘医生',
    doctorPhone: '13700001111',
    samplingTime: '2025-02-06 15:50:00',
    gender: '男',
    birthTime: '1988-07-25',
    age: 37,
    ageUnit: '岁',
    medicalAdvice: '神经系统检查'
  },
  {
    hospitalBarcode: '10007',
    specimenType: '精液',
    specimenSource: '男科',
    patientId: 'P007',
    patientName: '郑九',
    bedNumber: '707',
    patientPhone: '13833334444',
    department: '男科',
    doctor: '郭医生',
    doctorPhone: '13944445555',
    samplingTime: '2025-02-07 10:30:00',
    gender: '男',
    birthTime: '1993-09-18',
    age: 32,
    ageUnit: '岁',
    medicalAdvice: '生殖系统检查'
  },
  {
    hospitalBarcode: '10008',
    specimenType: '羊水',
    specimenSource: '妇产科',
    patientId: 'P008',
    patientName: '钱十',
    bedNumber: '808',
    patientPhone: '13622223333',
    department: '妇产科',
    doctor: '许医生',
    doctorPhone: '13533334444',
    samplingTime: '2025-02-08 14:10:00',
    gender: '女',
    birthTime: '1996-04-12',
    age: 29,
    ageUnit: '岁',
    medicalAdvice: '产前检查'
  },
  {
    hospitalBarcode: '10009',
    specimenType: '关节液',
    specimenSource: '骨科',
    patientId: 'P009',
    patientName: '孙十一',
    bedNumber: '909',
    patientPhone: '13755556666',
    department: '骨科',
    doctor: '马医生',
    doctorPhone: '13866667777',
    samplingTime: '2025-02-09 09:45:00',
    gender: '男',
    birthTime: '1991-12-08',
    age: 34,
    ageUnit: '岁',
    medicalAdvice: '关节疾病检查'
  },
  {
    hospitalBarcode: '10006',
    specimenType: '脑脊液',
    specimenSource: '神经内科',
    patientId: 'P006',
    patientName: '吴八',
    bedNumber: '606',
    patientPhone: '13477770000',
    department: '神经内科',
    doctor: '刘医生',
    doctorPhone: '13700001111',
    samplingTime: '2025-02-06 15:50:00',
    gender: '男',
    birthTime: '1988-07-25',
    age: 37,
    ageUnit: '岁',
    medicalAdvice: '神经系统检查'
  },
  
]);
const showList = ref<specimenData[]>([])

const search = () => {
  showList.value = list.value.filter(item => {
    return (checkParam.value.keyword == undefined || checkParam.value.keyword == '' ||
     checkParam.value.keyword != undefined && (item.hospitalBarcode == checkParam.value.keyword || item.patientName == checkParam.value.keyword )
    ) && (checkParam.value.startCreationTime == undefined || checkParam.value.startCreationTime != undefined && new Date(checkParam.value.startCreationTime) <= new Date(item.samplingTime))
    && (checkParam.value.endCreationTime == undefined || checkParam.value.endCreationTime != undefined && new Date(checkParam.value.endCreationTime) >= new Date(item.samplingTime))
  })
}
const scanRef = ref<HTMLElement | null>(null)
/**
 * 扫码回调
 * @param code 返回扫码内容 
 */
const getScanInfo = (code: string) => {
  if (!code) return
  ElMessageBox.confirm(`是否确认录入标本${code}？`, '', {
    showClose: false
  }).then(() => {
    list.value.push({
      hospitalBarcode: code,
      specimenType: '关节液',
      specimenSource: '骨科',
      patientId: 'P009',
      patientName: '孙十一',
      bedNumber: '909',
      patientPhone: '13755556666',
      department: '骨科',
      doctor: '马医生',
      doctorPhone: '13866667777',
      samplingTime: '2025-02-09 09:45:00',
      gender: '男',
      birthTime: '1991-12-08',
      age: 34,
      ageUnit: '岁',
      medicalAdvice: '关节疾病检查'
    });
    
    (scanRef.value as any)?.clear()
    search()
  })
 
}
onMounted(() => {
  search()
})
</script>


<style scoped>

</style>